package com.gable.report.service.impl;

import com.gable.report.dao.IChartsHospitalSearchDao;
import com.gable.report.model.ChartsPriceCategory;
import com.gable.report.model.ChartsSearchView;
import com.gable.report.service.ChartsHospitalSearchService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import static com.gable.report.util.ChartsUtil.getPinYin;


/**
 * 医院图表 搜索条件 sevice层实现
 * @author 杨青桦
 *
 */
@Service
public class ChartsHospitalSearchServiceImpl implements ChartsHospitalSearchService {
	// 日志记录
	private final Log logger = LogFactory.getLog(this.getClass());

	@Autowired
	private IChartsHospitalSearchDao iChartsHospitalSearchDao;


	@Override
	public List<ChartsSearchView> queryDepartmentsList(String hospitalId) {
		return getPinYin(iChartsHospitalSearchDao.queryDepartmentsList(hospitalId));
	}

	@Override
	public List<ChartsSearchView> queryFirstDeviceTypesList(String hospitalId) {
		return getPinYin(iChartsHospitalSearchDao.queryFirstDeviceTypesList(hospitalId));
	}

	@Override
	public List<ChartsSearchView> querySecondDeviceTypesList(String hospitalId, String typeId) {
		Map<String,String> paramsMap = new HashMap<String,String>();
		paramsMap.put("hospitalId",hospitalId);
		paramsMap.put("typeId",typeId);
		return getPinYin(iChartsHospitalSearchDao.querySecondDeviceTypesList(paramsMap));
	}

	@Override
	public List<ChartsSearchView> queryDeviceRiskLevels() {
		ChartsSearchView csv0 = new ChartsSearchView("0","〇级","zeroth");
		ChartsSearchView csv1 = new ChartsSearchView("1","Ⅰ级","first");
		ChartsSearchView csv2 = new ChartsSearchView("2","Ⅱ级","secondary");
		ChartsSearchView csv3 = new ChartsSearchView("3","Ⅲ级","tertiary");
		return Arrays.asList(csv3,csv2,csv1,csv0);
	}

	@Override
	public List<ChartsSearchView> queryDeviceBrandList(String hospitalId, String brandId) {
		Map<String,String> paramsMap = new HashMap<String,String>();
		paramsMap.put("hospitalId",hospitalId);
		//目前没有国产进口的维护，预留一个字段
		paramsMap.put("brandId",brandId);
		return getPinYin(iChartsHospitalSearchDao.queryDeviceBrandList(paramsMap));
	}

	@Override
	public List<ChartsSearchView> queryCurYears() {
		Calendar calendar = Calendar.getInstance();
		Integer year = calendar.get(Calendar.YEAR);
		List<ChartsSearchView> list = new ArrayList<>();
		for(int i=0;i<4;i++){
			ChartsSearchView obj = new ChartsSearchView(String.valueOf(year),String.valueOf(year)+"年",String.valueOf(year));
			year -= 1;
			list.add(obj);
		}
		return list;
	}

	@Override
	public List<ChartsSearchView> queryPriceCategory(String hospitalId) {
		//获取金额区间
		ChartsPriceCategory obj = iChartsHospitalSearchDao.queryPriceCategory(hospitalId);
		//组装筛选条件
		ChartsSearchView csv0 = new ChartsSearchView("0",String.valueOf(obj.getPriceDefault()/1000000),null);
		ChartsSearchView csv1 = new ChartsSearchView("1",String.valueOf(obj.getPriceMax()/1000000),null);
		ChartsSearchView csv2 = new ChartsSearchView("2",String.valueOf(obj.getPriceMin()/1000000),null);
		return Arrays.asList(csv0,csv1,csv2);
	}

	@Override
	public List<ChartsSearchView> queryMaintainerList(String hospitalId) {
		return iChartsHospitalSearchDao.queryMaintainerList(hospitalId);
	}

}
